package fenzhixianjie.tanglian.exer01;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt(), n = sc.nextInt();
        int startRow = sc.nextInt(), startCol = sc.nextInt();
        int endRow = sc.nextInt(), endCol = sc.nextInt();
        int[][] mat = new int[m][n];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                mat[i][j] = sc.nextInt();
            }
        }
        int[][] copy = new int[m][n];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                copy[i][j] = mat[i][j];
            }
        }
        Queue<int[]> queue = new LinkedList<>();
        int[][] nextPos = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
        boolean[][] flag = new boolean[m][n];
        queue.offer(new int[] {startRow, startCol});
        mat[startRow][startCol] = -2;
        flag[startRow][startCol] = true;
        int curStep = 1;
        boolean end = false;
        while (!queue.isEmpty()) {
            int size = queue.size();
            while (size > 0) {
                int[] top = queue.poll();
                for (int i = 0; i < 4; i++) {
                    int nextRow = top[0] + nextPos[i][0];
                    int nextCol = top[1] + nextPos[i][1];
                    if (nextRow >= 0 && nextRow < m && nextCol >= 0 && nextCol < n && !flag[nextRow][nextCol] && mat[nextRow][nextCol] == 0) {
                        if (nextRow == endRow && nextCol == endCol) {
                            end = true;
                            break;
                        }
                        queue.offer(new int[] {nextRow, nextCol});
                        flag[nextRow][nextCol] = true;
                        mat[nextRow][nextCol] = curStep;
                    }
                }
                if (end) {
                    break;
                }
                size--;
            }
            if (end) {
                break;
            }
            curStep++;
        }
        mat[endRow][endCol] = -3;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (mat[i][j] == curStep) {
                    mat[i][j] = copy[i][j];
                }
            }
        }
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n - 1; j++) {
                if (mat[i][j] == -2 || mat[i][j] == -3) {
                    if (mat[i][j] == -2) {
                        System.out.printf("%3c", 'a');
                    } else {
                        System.out.printf("%3c", 'b');
                    }
                } else {
                    System.out.printf("%3d", mat[i][j]);
                }
            }
            if (mat[i][n - 1] == -2 || mat[i][n - 1] == -3) {
                if (mat[i][n - 1] == -2) {
                    System.out.printf("%3c\n", 'a');
                } else {
                    System.out.printf("%3c\n", 'b');
                }
            } else {
                System.out.printf("%3d\n", mat[i][n - 1]);
            }
        }
    }
}
